﻿using System;
using System.Text;
using Asistente.Model.General;
using Asistente.Model.IFPUG.MeasureUtilities;

namespace Asistente.Model.IFPUG
{
    //Representa una funcion transaccional de IFPUG, EI, EO o EQ
    public class TransactionalFunction : IMeasurable
    {
        public int Det { get; set; }
        public int Ftr { get; set; }
        public TransactionalFunctionType Type { get; set; }

        public int Measure()
        {
            switch (Type)
            {
                case TransactionalFunctionType.Ei:
                    return IfpugMeasureManager.Instance.EiMeasure(Det, Ftr);
                case TransactionalFunctionType.Eo:
                    return IfpugMeasureManager.Instance.EoMeasure(Det, Ftr);
                case TransactionalFunctionType.Eq:
                    return IfpugMeasureManager.Instance.EqMeasure(Det, Ftr);
                default: throw new NotImplementedException(); //Solo hay los tres tipos anteriores
            }
        }

        public override string ToString()
        {
            StringBuilder content = new StringBuilder();
            content.Append("\t" + Type.ToString().ToUpper());
            content.Append("\t" + Det);
            content.Append("\t" + Ftr);
            return content.ToString();
        }

        internal string ToHtml()
        {
            StringBuilder content = new StringBuilder();
            content.Append("<td>");
            content.Append(Type.ToString().ToUpper());
            content.Append("</td>");
            content.Append("<td>");
            content.Append(Det);
            content.Append("</td>");
            content.Append("<td>");
            content.Append(Ftr);
            content.Append("</td>");
            return content.ToString();
        }
    }  
}
